/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1636345278719_302';

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  config.customLoader = {
    adapter: {
      // relative to app.config.baseDir
      directory: 'app/task',
      // if inject is ctx, it will use loadToContext
      inject: 'ctx',
      // whether load the directory of the framework and plugin
      loadunit: false,
      // you can also use other LoaderOptions
    },
  };

  config.redis = {
    client: {
      port: 6379,
      host: '127.0.0.1',
      password: null,
      db: 2,
    },
  };

  config.mongoose = {
    url: 'mongodb://127.0.0.1/egg_xgimi_app',
    options: {
      useNewUrlParser: true,
      useCreateIndex: true,
      useUnifiedTopology: true,
      useFindAndModify: false,
      bufferMaxEntries: 0,
      poolSize: 20,
    },
  };

  // 邮箱配置;
  config.mail_opts = {
    service: '163',
    host: 'smtp.163.com',
    port: 465,
    auth: {
      user: '13541863172@163.com',
      pass: 'hu13541863172',
    },
    ignoreTLS: true,
  };

  config.jwt = {
    secret: process.env['jwt.key'] || 'Great4-M',
    enable: true, // default is false
    match: '/jwt', // optional
  };

  config.cluster = {
    listen: {
      hostname: '0.0.0.0',
    },
  };


  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,OPTIONS,POST,DELETE,PATCH',
  };

  config.security = {
    csrf: {
      enable: false,
    },
  };

  config.multipart = {
    mode: 'file',
    fileSize: '100mb',
    fileExtensions: [
      '.apk',
      '.pptx',
      '.docx',
      '.csv',
      '.doc',
      '.ppt',
      '.pdf',
      '.pages',
      '.wav',
      '.mov',
      '.mp4',
      '.avi',
      '.rmvb',
      '.mkv',
      '.asf',
      '.wmv',
      '.png',
      '.jpg',
      '.jpeg',
      '.webp',
      '.gif',
    ], // 增加对 .apk 扩展名的支持
  };

  config.middleware = [ 'errorHandler', 'accessLog' ];

  config.bus = {
    debug: false, // Debug 模式下会打印更多日志信息
    concurrency: 4, // Bull 中队列处理的并发数：https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queueprocess
    listener: {
      ignore: null, // 忽略目录中的某些文件，https://eggjs.org/zh-cn/advanced/loader.html#ignore-string
      baseDir: 'listener',
      options: {
        // Bull Job 配置： https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queueadd
        attempts: 5,
        backoff: {
          delay: 3000,
          type: 'fixed',
        },
      },
    },
    job: {
      ignore: null, // 忽略目录中的某些文件，https://eggjs.org/zh-cn/advanced/loader.html#ignore-string
      baseDir: 'job',
      options: {
        // Bull Job 配置： https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queueadd
        attempts: 5,
        backoff: {
          delay: 3000,
          type: 'fixed',
        },
      },
    },
    bull: {
      // Bull 队列配置：https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queue
      redis: config.redis.client,
    },

    queue: {
      default: 'superApp', // 默认队列名称
      prefix: 'superApp', // 队列前缀
    },
  };

  return {
    ...config,
    ...userConfig,
  };
};
